﻿using System.Windows.Input;
using TestBat.IModels.Domain;
using TestBat.IModels.Models;
using TestBat.IViewModels.Factories;
using TestBat.IViewModels.Workspaces.Tasks;
using TestBat.ViewModels.Attributes;
using TestBat.ViewModels.Base.Commands;

namespace TestBat.ViewModels.Workspaces.Tasks
{
    public class LeafTaskFolderViewModel : TaskFolderViewModel, ILeafTaskFolderViewModel
    {
        public LeafTaskFolderViewModel(ILeafTaskFolder taskFolder, ITaskFolderModel taskFolderModel, ITaskViewModelFactory taskViewModelFactory, ILeafTaskFolderViewModelFactory taskFolderViewModelFactory)
            : base(taskFolder, taskFolderModel, taskViewModelFactory, taskFolderViewModelFactory)
        {
        }

        public virtual ICommand DeleteCommand
        {
            get { return new RelayCommand(c => Delete()); }
        }

        [BusinessErrorDialog]
        [YesNoDialog("Do your really want to delete this task folder?")]
        protected virtual void Delete()
        {
            taskFolderModel.Delete(taskFolder);

            if (OnRemove != null)
                OnRemove(this);
        }

        public virtual ICommand SaveCommand
        {
            get { return new RelayCommand(c => Save()); }
        }

        [BusinessErrorDialog]
        [ValidationErrorDialog]
        protected virtual void Save()
        {
            taskFolderModel.Save(taskFolder);
        }
    }
}
